use common::pagination::Pagination;
use dao::POST_DAO;
use model::post::{Post, PostNew, PostPage, PostUpdate};

pub struct PostService;

impl PostService {

    pub fn page(&self, page: PostPage) -> Pagination<Post> {
        POST_DAO.page(page)
    }

    pub fn list_posts(&self) -> Vec<Post> {
        POST_DAO.list_posts()
    }

    pub fn get_by_id(&self, id: i32) -> Result<Post, diesel::result::Error> {
        POST_DAO.get_by_id(id)
    }

    pub fn add(&self, post: &PostNew) {
        POST_DAO.add(post);
    }

    pub fn update(&self, post: &PostUpdate) {
        POST_DAO.update(post)
    }

    pub fn delete(&self, id: i32) {
        POST_DAO.delete(id)
    }
}
